import 'dart:async';

import 'package:auto_route/auto_route.dart';
import 'package:distribution_mall_flutter/assets.dart';
import 'package:distribution_mall_flutter/constant/constant.dart';
import 'package:distribution_mall_flutter/constant/image_constant.dart';
import 'package:distribution_mall_flutter/utils/image_loader.dart';
import 'package:distribution_mall_flutter/router/router.gr.dart';
import 'package:distribution_mall_flutter/utils/storage.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

@RoutePage()
class SplashPage extends StatefulWidget {
  final String? saleItemId;
  const SplashPage({super.key, @pathParam this.saleItemId});

  @override
  State<SplashPage> createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {
  Timer? timer;

  @override
  void initState() {
    super.initState();
    if (widget.saleItemId != ':saleItemId' &&
        widget.saleItemId?.isNotEmpty == true) {
      EPstorage.route.put(RouteBoxKey.isH5PDetail, widget.saleItemId);
    }
    timer = Timer(const Duration(seconds: 1), () {
      appRouter.replace(const HomeRoute());
    });
  }

  @override
  void dispose() {
    timer?.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SizedBox(
        width: double.infinity,
        child: Column(
          children: [
            Container(
                margin: EdgeInsets.only(top: 139.h),
                child: Image.asset(
                  Assets.assets_icons_splash_logo_png,
                  width: 345.w,
                )),
            const Spacer(),
            SafeArea(
                top: false,
                bottom: true,
                child: Container(
                  margin: EdgeInsets.only(bottom: 60.h),
                  child: Image.asset(
                    Assets.assets_icons_splash_text_png,
                    width: 339.w,
                  ),
                )
                // RichText(
                //   text: const TextSpan(children: [
                //     TextSpan(
                //         text: 'Easy ',
                //         style:
                //             TextStyle(fontSize: 21, color: Color(0xFFFA6A0B))),
                //     TextSpan(
                //         text: 'with epal!',
                //         style:
                //             TextStyle(fontSize: 21, color: Color(0xFF074084))),
                //   ]),
                // ),
                ),
            // ),
          ],
        ),
      ),
    );
  }
}
